package com.yulan.two_pair;

import org.junit.Test;

/**
 * 713. 乘积小于K的子数组
 */
public class LeetCode_713 {
    public int numSubarrayProductLessThanK(int[] nums, int k) {
        int product = 1;
        int ans = 0;
        int l = 0, r = 0;
        while(r < nums.length){
            product *= nums[r++];
            //直到积大于k才开始从左边缩小窗口
            while(product >= k && l < r){
                product /= nums[l++];
            }

            ans += r - l;
        }
        return ans;
    }

    @Test
    public void test(){
        int[] arr = {10,5,2,6};
        System.out.println(numSubarrayProductLessThanK(arr,100));
    }


}
